import {
    TripleDES,
    mode,
    pad,
    enc
} from 'crypto-js';
Date.prototype.Format = function (formatStr) {
    var str = formatStr
    var Week = ['日', '一', '二', '三', '四', '五', '六']

    str = str.replace(/yyyy|YYYY/, this.getFullYear())
    str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100))

    str = str.replace(/MM/, (this.getMonth() + 1) > 9 ? (this.getMonth() + 1).toString() : '0' + (this.getMonth() + 1))
    str = str.replace(/M/g, (this.getMonth() + 1))

    str = str.replace(/w|W/g, Week[this.getDay()])

    str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate())
    str = str.replace(/d|D/g, this.getDate())

    str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours())
    str = str.replace(/h|H/g, this.getHours())
    str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes())
    str = str.replace(/m/g, this.getMinutes())

    str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds())
    str = str.replace(/s|S/g, this.getSeconds())

    return str
}
const doExchange = function (arr) {
    var len = arr.length;
    // 当数组大于等于2个的时候
    if (len >= 2) {
        // 第一个数组的长度
        var len1 = arr[0].length;
        // 第二个数组的长度
        var len2 = arr[1].length;
        // 2个数组产生的组合数
        var lenBoth = len1 * len2;
        //  申明一个新数组
        var items = new Array(lenBoth);
        // 申明新数组的索引
        var index = 0;
        for (var i = 0; i < len1; i++) {
            for (var j = 0; j < len2; j++) {
                if (arr[0][i] instanceof Array) {
                    items[index] = arr[0][i].concat(arr[1][j]);
                } else {
                    items[index] = [arr[0][i]].concat(arr[1][j]);
                }
                index++;
            }
        }
        var newArr = new Array(len - 1);
        for (var i = 2; i < arr.length; i++) {
            newArr[i - 1] = arr[i];
        }
        newArr[0] = items;
        return doExchange(newArr);
    } else {
        return arr[0];
    }
}
const formatNumber = (value) => {
	let numerical=[];
	  let k = 10000,
	      sizes = ['', '万', '亿', '万亿'],
	      i;
	      if(value < k){
	        numerical=Number(value).toFixed(2)
	      }else{
	          i = Math.floor(Math.log(value) / Math.log(k)); 
	          numerical=((value / Math.pow(k, i))).toFixed(2)+sizes[i];
	      }
	      
	return numerical;
}

const key = enc.Utf8.parse("code2023030108145310241024");
const iv = enc.Utf8.parse('10241024');
const encryptByEnDES = function (data) {
    data = enc.Utf8.parse(data);
    let tmpDES = TripleDES.encrypt(data, key, {
        iv: iv,
        mode: mode.CBC,
        padding: pad.Pkcs7
    });
    return tmpDES.toString()
}
const uploadImageCheck=function(file){
    if(file.size>10*1024*1024){
        Message({
            type:"error",
            message:"请上传10M内图片"
        })
        return false;
    }
    if(file.type.indexOf('image')>-1){
        return true;
    }else{
        Message({
            type:"error",
            message:"请上传图片格式文件"
        })
        return false;
    }
}
const uploadVideoCheck=function(file){
    if(file.type.indexOf('video')>-1){
        return true;
    }else{
        Message({
            type:"error",
            message:"请上传视频格式文件"
        })
        return false;
    }
}
export default {
    doExchange,
    encryptByEnDES,
    uploadImageCheck,
    formatNumber
}